try
    
% Clear the workspace
close all;
clearvars;
sca;
clear all;


%%
%
Screen('Preference', 'SkipSyncTests', 1);

% Set the screen number to the external secondary monitor if there is one
% connected
screenNumber = max(Screen('Screens'));

% Define black, white and grey
white = WhiteIndex(screenNumber);
black = BlackIndex(screenNumber);

% Open the screen
[w,rect]=Screen('OpenWindow',screenNumber,white);
HideCursor;
ListenChar(2);

%creates a keyboard queue
[kbd_devs, name] = GetKeyboardIndices;
keys=[30:40];%%all keys on right hand, can be found by running kbdemo
%keylist=zeros(1,256);%%create a list of 256 zeros
%keylist(keys)=1;
keylist=ones(1,256);
KbQueueCreate(kbd_devs(end),keylist);

% Flip to clear
Screen('Flip', w);

% Query the frame duration
ifi = Screen('GetFlipInterval', w);

% Set the text size and font
Screen('TextSize',w, 30);
Screen('TextFont',w, 'Courier New');
Screen('TextStyle', w, 1);

% Get the centre coordinate of the window
[xCenter, yCenter] = RectCenter(rect);

% Get the screen width and height
screen_w=rect(3);
screen_h=rect(4);

% Set vertical and horizontal margins
%v_margin=50;
%h_margin=((screen_w - (screen_h-(2*v_margin)))/2);

%set the location of the text
%Screen 1
objs_left_sx=(screen_w/4)-100;
objs_right_sx=xCenter+(screen_w/4)-20;
%objs_sy=yCenter+50;
objs_sy=yCenter;
setup_text=yCenter-50;

%set where to wrap the text
wrapat = 74;
wrapat2= 70;

% Query the maximum priority level
topPriorityLevel = MaxPriority(w);

% Set the blend funciton for the screen
Screen('BlendFunction', w, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');

%%
%Set study parameters
num_trials=16;
num_runs=14;

%set up timing dimensions

objs_time=4;
choice_time=4;
quest_time=8;
iti=2;

%Load Images and Set Prefs
ball=imread('./images/ball.jpg','jpg');
plant=imread('./images/plant.jpg','jpg');
lipstick=imread('./images/lipstick.jpg','jpg');
compass=imread('./images/compass.jpg','jpg');
trap=imread('./images/trap.jpg','jpg');
can=imread('./images/can.jpg','jpg');

%get image info
img_info = imfinfo('./images/ball.jpg');

%pull out the image size
img_w = img_info.Width;
img_h = img_info.Height;

%set image locations for objects screen %Left, Top, Right, Bottom
objs_loc_left=[(objs_left_sx),yCenter+50,(objs_left_sx+img_w),(yCenter+img_h)];
objs_loc_center=[(xCenter-.5*img_w),yCenter+50,(xCenter+.5*img_w),(yCenter+img_h)];
objs_loc_right=[(objs_right_sx),yCenter+50,(objs_right_sx+img_w),(yCenter+img_h)];

choice_loc=[(xCenter-.5*img_w),yCenter+75,(xCenter+.5*img_w),(yCenter+img_h+25)];

%%
%Instructions Text
choices='Strongly disagree            Neutral            Strongly agree\n\n1          2          3         4          5';

inst1='Imagine there is a reality TV show where contestants will spend one month alone on a desert island and the challenge is to survive.\n\n\n\n\nClick any key to continue.';
inst2='Contestants are not allowed to bring anything but the clothes they are wearing.\n\nHowever, the producers will begin the show by offering each contestant a "survival pack" with three items.\n\nIn order to keep things interesting, the survival packs contain some items that would be quite useful on a desert island and some items that would not be useful at all.\n\nIn addition, contestants are only allow to bring some of the things from the survival pack onto the desert island.\n\n\n\n\nClick any key to continue.';

%keep_rej_first=randperm(2,1);
%if keep_rej_first==1
inst3a='Sometimes, the contestants are allowed to choose exactly one of the items to KEEP and bring on the island.\n\nIn this case, the contestant must REJECT the other two items and leave them behind.\n\nThis is called the KEEP game.\n\n\n\n\nClick any key to continue.';
inst4a='For example, imagine you are watching one contestant, Joe, open the survival pack on TV.\n\nYou will find out what is in the survival pack and what Joe decided to KEEP.\n\n\n\n\nClick any key to continue.'; 
inst5a='For instance, Joe''s survival pack contains:\n\nyo-yo     tent        tennis ball\n\n\n\nAfter considering all three options,\nJoe decided to KEEP the:\n\ntent\n\n\n\n\nClick any key to continue.';
inst6a='Then you will see a comment about it.\n\nYour job is to say how strongly you agree with the comment.\n\nYou will be responding on a 1-5 scale using the button box in your right hand.\n\n1 (thumb) = Strongly disagree\n2 (index finger) = Somewhat disagree\n3 (middle finger) = Neutral\n4 (ring finger) = Somewhat agree\n5 (pinky) = Strongly agree\n\n\n\n\nClick any key to see the comment and make a choice.';
inst7a=['Comment: ''''Seems like Joe made a good choice.''''\n\n',choices];

inst3b='Other times, instead of getting to KEEP one item from their survival pack, contestants must choose one item to REJECT.\n\nIn this case, each contestant is allowed to choose exactly two of the items to KEEP and bring on the island but they must REJECT one of the items and leave it behind.\n\nThis is called the REJECT game.\n\n\n\n\nClick any key to continue.';
inst4b='For example, imagine you are watching one contestant, Jane, open the survival pack on TV.\n\nOnce again you will find out what is in the survival pack and what Jane decided to REJECT.\n\n\n\n\nClick any key to continue.'; 
inst5b='For instance, Jane''s survival pack contains:\n\nanimal trap     tent        tennis ball\n\n\n\nAfter considering all three options,\nJane decided to REJECT the:\n\nanimal trap\n\n\n\n\nClick any key to continue.';
inst6b='Then you will see a comment about it.\n\nYour job is to say how strongly you agree with the comment.\n\nYou will be responding on a 1-5 scale using the button box in your right hand.\n\n1 (thumb) = Strongly disagree\n2 (index finger) = Somewhat disagree\n3 (middle finger) = Neutral\n4 (ring finger) = Somewhat agree\n5 (pinky) = Strongly agree\n\n\n\n\nClick any key to see the comment and make a choice.';
inst7b=['Comment: ''''Seems like Jane made a bad choice.''''\n\n',choices];

inst12='First, let''s do a few practice trials of the KEEP game.\n\nRemember, in this game, the contestants get to KEEP one item from their survival packs to take on the island but they must REJECT the other two and leave them behind.\n\n\n\n\nClick any key to begin the first practice trial.';

%ball plant can - can
prac1a='Alicia''s survival pack contains:';
prac1aleft='soccer ball';
prac1acenter='house plant';
prac1aright='can of food';
prac1b='After considering all three options,\nAlicia decided to KEEP the:\n\ncan of food';
prac1c=['I think Alicia KEPT the can of food.\n\n',choices];

%compass ball trap - compass
prac2a='Jerry''s survival pack contains:';
prac2aleft='compass';
prac2acenter='soccer ball';
prac2aright='animal trap';
prac2b='After considering all three options,\nJerry decided to KEEP the:\n\ncompass';
prac2c=['Seems like Jerry HAD TO KEEP the compass.\n\n',choices];

%lipstick ball trap - trap
prac3a='Kelly''s survival pack contains:';
prac3aleft='lipstick';
prac3acenter='soccer ball';
prac3aright='animal trap';
prac3b='After considering all three options,\nKelly decided to KEEP the:\n\nanimal trap';
prac3c=['I think Kelly DIDN''T HAVE TO KEEP the animal trap.\n\n',choices];

%compass plant lipstick - lipstick
prac4a='Pete''s survival pack contains:';
prac4aleft='compass';
prac4acenter='house plant';
prac4aright='lipstick';
prac4b='After considering all three options,\nPete decided to KEEP the:\n\nlipstick';
prac4c=['Seems like Pete DIDN''T KEEP the house plant.\n\n',choices];

inst13='Now let''s do a few practice trials of the REJECT game.\n\nRemember, in this game, the contestants must REJECT one item from their survival packs and leave it behind but they get to KEEP the other two and bring them on the island.\n\n\nClick any key to begin the first practice trial.';

%lipstick can plant - plant
prac5a='Doug''s survival pack contains:';
prac5aleft='lipstick';
prac5acenter='can of food';
prac5aright='house plant';
prac5b='After considering all three options,\nDoug decided to REJECT the:\n\nhouse plant';
prac5c=['Seems like Doug REJECTED the houseplant.\n\n',choices];

%can ball trap - trap
prac6a='Kerry''s survival pack contains:';
prac6aleft='can of food';
prac6acenter='soccer ball';
prac6aright='animal trap';
prac6b='After considering all three options,\nKerry decided to REJECT the:\n\nanimal trap';
prac6c=['I think Kerry DIDN''T HAVE TO REJECT the animal trap.\n\n',choices];

%ball can plant - ball
prac7a='Alfonso''s survival pack contains:';
prac7aleft='soccer ball';
prac7acenter='can of food';
prac7aright='house plant';
prac7b='After considering all three options,\nAlfonso decided to REJECT the:\n\nsoccer ball';
prac7c=['Seems like Alfonso DIDN''T REJECT the can of food.\n\n',choices];

%compass ball lipstick - lipstick
prac8a='Ruby''s survival pack contains:';
prac8aleft='compass';
prac8acenter='soccer ball';
prac8aright='lipstick';
prac8b='After considering all three options,\nRuby decided to REJECT the:\n\nlipstick';
prac8c=['I think Ruby HAD TO REJECT the lipstick.\n\n',choices];

%{
else    
inst3a='Sometimes, the contestants must choose exactly one of the items to REJECT and leave behind.\n\nIn this case, the contestant is allowed to KEEP two of the items and bring them on the island.\n\nThis is called the REJECT game.\n\n\n\n\nClick any key to continue.';
inst4a='For example, imagine you are watching one contestant, Jane, open the survival pack on TV.\n\nYou will find out what is in the survival pack and what Jane decided to REJECT.\n\n\n\n\nClick any key to continue.'; 
inst5a='For instance, Jane''s survival pack contains:\n\nanimal trap     tent        tennis ball\n\n\n\nAfter considering all three options,\nJane decided to REJECT the:\n\nanimal trap\n\n\n\n\nClick any key to continue.';
inst6a='Then you will see a comment about it.\n\nYour job is to say how strongly you agree with the comment.\n\nYou will be responding on a 1-5 scale using the keys at the top of your keyboard.\n\n1 = Strongly disagree\n2 = Somewhat disagree\n3 = Neither agree nor disagree\n4 = Somewhat agree\n5 = Strongly agree\n\n\n\n\nClick any key to see the comment and make a choice.';
inst7a=['Comment: ''''Seems like Jane made a bad choice.''''\n\n',choices];   

inst3b='Other times, instead of having to REJECT one of the items from their survival pack, contestants get to choose one item to KEEP.\n\nIn this case, each contestant is allowed to choose exactly one of the items to KEEP and bring on the island but they must REJECT the other two items and leave them behind.\n\nThis is called the KEEP game.\n\n\n\n\nClick any key to continue.';
inst4b='For example, imagine you are watching one contestant, Joe, open the survival pack on TV.\n\nOnce again, you will find out what is in the survival pack and what Joe decided to KEEP.\n\n\n\n\nClick any key to continue.'; 
inst5b='For instance, Joe''s survival pack contains:\n\nyo-yo     tent        tennis ball\n\n\n\nAfter considering all three options,\nJoe decided to KEEP the:\n\ntent\n\n\n\n\nClick any key to continue.';
inst6b='Then you will see a comment about it.\n\nYour job is to say how strongly you agree with the comment.\n\nYou will be responding on a 1-5 scale using the keys at the top of your keyboard.\n\n1 = Strongly disagree\n2 = Somewhat disagree\n3 = Neither agree nor disagree\n4 = Somewhat agree\n5 = Strongly agree\n\n\n\n\nClick any key to see the comment and make a choice.';
inst7b=['Comment: ''''Seems like Joe made a good choice!''''\n\n',choices];

inst12='First, let''s do a few practice trials of the REJECT game.\n\nRemember, in this game, the contestants must REJECT one item from their survival packs and leave it behind but they get to KEEP the other two and bring them on the island.\n\n\n\n\nClick any key to begin the first practice trial.';

prac1a='Doug''s survival pack contains:\n\nlipstick          can of food          house plant';
prac1b='After considering all three options,\nDoug decided to REJECT the:\n\nhouse plant';
prac1c=['Seems like Doug REJECTED the chewing gum.\n\n',choices];

prac2a='Kerry''s survival pack contains:\n\ncan of food          soccer ball          animal trap';
prac2b='After considering all three options,\nKerry decided to REJECT the:\n\nanimal trap';
prac2c=['I think Kerry DIDN''T HAVE TO REJECT the animal trap.\n\n',choices];

prac3a='Alfonso''s survival pack contains:\n\nsoccer ball          can of food          house plant';
prac3b='After considering all three options,\nAlfonso decided to REJECT the:\n\nsoccer ball';
prac3c=['Seems like Alfonso DIDN''T REJECT the can of food.\n\n',choices];

prac4a='Ruby''s survival pack contains:\n\ncompass          soccer ball          lipstick';
prac4b='After considering all three options,\nRuby decided to REJECT the:\n\nlipstick';
prac4c=['I think Ruby HAD TO REJECT the lipstick.\n\n',choices];

inst13='Now let''s do a few practice trials of the KEEP game.\n\nRemember, in this game, the contestants get to KEEP one item from their survival packs to take on the island but they must REJECT the other two and leave them behind.\n\n\nClick any key to begin the first practice trial.';

prac5a='Alicia''s survival pack contains:\n\nsoccer ball          house plant          can of food';
prac5b='After considering all three options,\nAlicia decided to KEEP the:\n\ncan of food';
prac5c=['I think Alicia KEPT the can of food.\n\n',choices];

prac6a='Jerry''s survival pack contains:\n\ncompass          soccer ball          animal trap';
prac6b='After considering all three options,\nJerry decided to KEEP the:\n\ncompass';
prac6c=['Seems like Jerry HAD TO KEEP the compass.\n\n',choices];

prac7a='Kelly''s survival pack contains:\n\nlipstick          soccer ball          animal trap';
prac7b='After considering all three options,\nKelly decided to KEEP the:\n\nanimal trap';
prac7c=['I think Kelly DIDN''T HAVE TO KEEP the animal trap.\n\n',choices];

prac8a='Pete''s survival pack contains:\n\ncompass          house plant          lipstick';
prac8b='After considering all three options,\nPete decided to KEEP the:\n\nlipstick';
prac8c=['Seems like Pete DIDN''T KEEP the house plant.\n\n',choices];

end
%}

inst8='The contestants'' decisions about what to keep and what to reject is very important.\n\nIn the past, people have not made it to the end of the month if they haven''t kept or rejected the right things.\n\n\n\n\nClick any key to continue.';

inst9='In this task you will see contestants'' decisions in both the KEEP and the REJECT games.\n\nFor both games, you will see the name of a contestant, the items in their survival pack, and what they decide to keep or reject.\n\nYou will then see a comment and be asked how strongly you agree with that comment.\n\n\n\n\nClick any key to continue.';
inst10='While you are going through this task, the screens will advance automatically.\n\nOnce you have input your answer by pressing one of the buttons on the button box, you may have to wait a while before the screen advances automatically.\n\nNOTE: Once you enter your response, it may be several seconds before anything happens. The computer will record your response and the screen will advance once the question has been on the screen for 8 seconds.\n\n\n\n\nPress any key to continue.';
inst11='Please be aware that each comment may be different in very subtle ways, so please pay careful attention to whether the contestant is playing the KEEP or REJECT game, what was in the survival pack, and what each comment says.\n\n\n\n\nClick any key to try a few more trials.';

instend='You have now finished with the instructions. If the scan has not finished, please wait until it does. Once the scan finishes an experimenter will check in with you.';

%%
%Display instructions
KbQueueFlush(kbd_devs(end));
KbQueueStart(kbd_devs(end)); 
DrawFormattedText(w,inst1,'center','center',black,wrapat2);
Screen('Flip',w);
KbQueueWait(kbd_devs(end));
WaitSecs(.5);
KbQueueStop(kbd_devs(end));

KbQueueFlush(kbd_devs(end));
KbQueueStart(kbd_devs(end)); 
DrawFormattedText(w,inst2,'center','center',black,wrapat2);
Screen('Flip',w);
KbQueueWait(kbd_devs(end));
WaitSecs(.5);
KbQueueStop(kbd_devs(end));

KbQueueFlush(kbd_devs(end));
KbQueueStart(kbd_devs(end)); 
DrawFormattedText(w,inst3a,'center','center',black,wrapat2);
Screen('Flip',w);
KbQueueWait(kbd_devs(end));
WaitSecs(.5);
KbQueueStop(kbd_devs(end));

KbQueueFlush(kbd_devs(end));
KbQueueStart(kbd_devs(end)); 
DrawFormattedText(w,inst4a,'center','center',black,wrapat2);
Screen('Flip',w);
KbQueueWait(kbd_devs(end));
WaitSecs(.5);
KbQueueStop(kbd_devs(end));

KbQueueFlush(kbd_devs(end));
KbQueueStart(kbd_devs(end)); 
DrawFormattedText(w,inst5a,'center','center',black,wrapat2);
Screen('Flip',w);
KbQueueWait(kbd_devs(end));
WaitSecs(.5);
KbQueueStop(kbd_devs(end));

KbQueueFlush(kbd_devs(end));
KbQueueStart(kbd_devs(end)); 
DrawFormattedText(w,inst6a,'center','center',black,wrapat2);
Screen('Flip',w);
KbQueueWait(kbd_devs(end));
WaitSecs(.5);
KbQueueStop(kbd_devs(end));

KbQueueFlush(kbd_devs(end));
KbQueueStart(kbd_devs(end)); 
DrawFormattedText(w,inst7a,'center','center',black,wrapat2);
Screen('Flip',w);
KbQueueWait(kbd_devs(end));
WaitSecs(.5);
KbQueueStop(kbd_devs(end));

KbQueueFlush(kbd_devs(end));
KbQueueStart(kbd_devs(end)); 
DrawFormattedText(w,inst3b,'center','center',black,wrapat2);
Screen('Flip',w);
KbQueueWait(kbd_devs(end));
WaitSecs(.5);
KbQueueStop(kbd_devs(end));

KbQueueFlush(kbd_devs(end));
KbQueueStart(kbd_devs(end)); 
DrawFormattedText(w,inst4b,'center','center',black,wrapat2);
Screen('Flip',w);
KbQueueWait(kbd_devs(end));
WaitSecs(.5);
KbQueueStop(kbd_devs(end));

KbQueueFlush(kbd_devs(end));
KbQueueStart(kbd_devs(end)); 
DrawFormattedText(w,inst5b,'center','center',black,wrapat2);
Screen('Flip',w);
KbQueueWait(kbd_devs(end));
WaitSecs(.5);
KbQueueStop(kbd_devs(end));

KbQueueFlush(kbd_devs(end));
KbQueueStart(kbd_devs(end)); 
DrawFormattedText(w,inst6b,'center','center',black,wrapat2);
Screen('Flip',w);
KbQueueWait(kbd_devs(end));
WaitSecs(.5);
KbQueueStop(kbd_devs(end));

KbQueueFlush(kbd_devs(end));
KbQueueStart(kbd_devs(end)); 
DrawFormattedText(w,inst7b,'center','center',black,wrapat2);
Screen('Flip',w);
KbQueueWait(kbd_devs(end));
WaitSecs(.5);
KbQueueStop(kbd_devs(end));

KbQueueFlush(kbd_devs(end));
KbQueueStart(kbd_devs(end)); 
DrawFormattedText(w,inst8,'center','center',black,wrapat2);
Screen('Flip',w);
KbQueueWait(kbd_devs(end));
WaitSecs(.5);
KbQueueStop(kbd_devs(end));

KbQueueFlush(kbd_devs(end));
KbQueueStart(kbd_devs(end)); 
DrawFormattedText(w,inst9,'center','center',black,wrapat2);
Screen('Flip',w);
KbQueueWait(kbd_devs(end));
WaitSecs(.5);
KbQueueStop(kbd_devs(end));

KbQueueFlush(kbd_devs(end));
KbQueueStart(kbd_devs(end)); 
DrawFormattedText(w,inst10,'center','center',black,wrapat2);
Screen('Flip',w);
KbQueueWait(kbd_devs(end));
WaitSecs(.5);
KbQueueStop(kbd_devs(end));

KbQueueFlush(kbd_devs(end));
KbQueueStart(kbd_devs(end)); 
DrawFormattedText(w,inst11,'center','center',black,wrapat2);
Screen('Flip',w);
KbQueueWait(kbd_devs(end));
WaitSecs(.5);
KbQueueStop(kbd_devs(end));

KbQueueFlush(kbd_devs(end));
KbQueueStart(kbd_devs(end)); 
DrawFormattedText(w,inst12,'center','center',black,wrapat2);
Screen('Flip',w);
KbQueueWait(kbd_devs(end));
WaitSecs(.5);
KbQueueStop(kbd_devs(end));

%ball plant can - can
tic;
while toc < objs_time
    Screen('PutImage',w,ball,objs_loc_left);
    Screen('PutImage',w,plant,objs_loc_center);
    Screen('PutImage',w,can,objs_loc_right);
    DrawFormattedText(w,prac1a,'center',setup_text,black,wrapat);
    DrawFormattedText(w,prac1aleft,objs_left_sx,objs_sy,black,wrapat);
    DrawFormattedText(w,prac1acenter,'center',objs_sy,black,wrapat);
    DrawFormattedText(w,prac1aright,objs_right_sx,objs_sy,black,wrapat);
    Screen('Flip',w);
end

tic;
while toc < choice_time
    Screen('PutImage',w,can,choice_loc);
    DrawFormattedText(w,prac1b,'center','center',black,wrapat);
    Screen('Flip', w);
end


tic;
while toc < quest_time
    DrawFormattedText(w,prac1c,'center','center',black,wrapat);
    Screen('Flip',w);
end

tic;
while toc < iti
    DrawFormattedText(w,'+','center','center',black,wrapat);
    Screen('Flip',w);
end

%compass ball trap - compass
tic;
while toc < objs_time
    Screen('PutImage',w,compass,objs_loc_left);
    Screen('PutImage',w,ball,objs_loc_center);
    Screen('PutImage',w,trap,objs_loc_right);
    DrawFormattedText(w,prac2a,'center',setup_text,black,wrapat);
    DrawFormattedText(w,prac2aleft,objs_left_sx,objs_sy,black,wrapat);
    DrawFormattedText(w,prac2acenter,'center',objs_sy,black,wrapat);
    DrawFormattedText(w,prac2aright,objs_right_sx,objs_sy,black,wrapat);
    Screen('Flip',w);
end

tic;
while toc < choice_time
    Screen('PutImage',w,compass,choice_loc);
    DrawFormattedText(w,prac2b,'center','center',black,wrapat);
    Screen('Flip', w);
end

tic;
while toc < quest_time
    DrawFormattedText(w,prac2c,'center','center',black,wrapat);
    Screen('Flip',w);
end

tic;
while toc < iti
    DrawFormattedText(w,'+','center','center',black,wrapat);
    Screen('Flip',w);
end

%lipstick ball trap - trap
tic;
while toc < objs_time
    Screen('PutImage',w,lipstick,objs_loc_left);
    Screen('PutImage',w,ball,objs_loc_center);
    Screen('PutImage',w,trap,objs_loc_right);
    DrawFormattedText(w,prac3a,'center',setup_text,black,wrapat);
    DrawFormattedText(w,prac3aleft,objs_left_sx,objs_sy,black,wrapat);
    DrawFormattedText(w,prac3acenter,'center',objs_sy,black,wrapat);
    DrawFormattedText(w,prac3aright,objs_right_sx,objs_sy,black,wrapat);
    Screen('Flip',w);
end

tic;
while toc < choice_time
    Screen('PutImage',w,trap,choice_loc);
    DrawFormattedText(w,prac3b,'center','center',black,wrapat);
    Screen('Flip', w);
end

tic;
while toc < quest_time
    DrawFormattedText(w,prac3c,'center','center',black,wrapat);
    Screen('Flip',w);
end

tic;
while toc < iti
    DrawFormattedText(w,'+','center','center',black,wrapat);
    Screen('Flip',w);
end

%compass plant lipstick - lipstick
tic;
while toc < objs_time
    Screen('PutImage',w,compass,objs_loc_left);
    Screen('PutImage',w,plant,objs_loc_center);
    Screen('PutImage',w,lipstick,objs_loc_right);
    DrawFormattedText(w,prac4a,'center',setup_text,black,wrapat);
    DrawFormattedText(w,prac4aleft,objs_left_sx,objs_sy,black,wrapat);
    DrawFormattedText(w,prac4acenter,'center',objs_sy,black,wrapat);
    DrawFormattedText(w,prac4aright,objs_right_sx,objs_sy,black,wrapat);
    Screen('Flip',w);
end

tic;
while toc < choice_time
    Screen('PutImage',w,lipstick,choice_loc);
    DrawFormattedText(w,prac4b,'center','center',black,wrapat);
    Screen('Flip', w);
end

tic;
while toc < quest_time
    DrawFormattedText(w,prac4c,'center','center',black,wrapat);
    Screen('Flip',w);
end

tic;
while toc < iti
    DrawFormattedText(w,'+','center','center',black,wrapat);
    Screen('Flip',w);
end

KbQueueFlush(kbd_devs(end));
KbQueueStart(kbd_devs(end)); 
DrawFormattedText(w,inst13,'center','center',black,wrapat);
Screen('Flip',w);
KbQueueWait(kbd_devs(end));
WaitSecs(.5);
KbQueueStop(kbd_devs(end));

%lipstick can plant - plant
tic;
while toc < objs_time
    Screen('PutImage',w,lipstick,objs_loc_left);
    Screen('PutImage',w,can,objs_loc_center);
    Screen('PutImage',w,plant,objs_loc_right);
    DrawFormattedText(w,prac5a,'center',setup_text,black,wrapat);
    DrawFormattedText(w,prac5aleft,objs_left_sx,objs_sy,black,wrapat);
    DrawFormattedText(w,prac5acenter,'center',objs_sy,black,wrapat);
    DrawFormattedText(w,prac5aright,objs_right_sx,objs_sy,black,wrapat);
    Screen('Flip',w);
end

tic;
while toc < choice_time
    Screen('PutImage',w,plant,choice_loc);
    DrawFormattedText(w,prac5b,'center','center',black,wrapat);
    Screen('Flip', w);
end

tic;
while toc < quest_time
    DrawFormattedText(w,prac5c,'center','center',black,wrapat);
    Screen('Flip',w);
end  

tic;
while toc < iti
    DrawFormattedText(w,'+','center','center',black,wrapat);
    Screen('Flip',w);
end

%can ball trap - trap
tic;
while toc < objs_time
    Screen('PutImage',w,can,objs_loc_left);
    Screen('PutImage',w,ball,objs_loc_center);
    Screen('PutImage',w,trap,objs_loc_right);
    DrawFormattedText(w,prac6a,'center',setup_text,black,wrapat);
    DrawFormattedText(w,prac6aleft,objs_left_sx,objs_sy,black,wrapat);
    DrawFormattedText(w,prac6acenter,'center',objs_sy,black,wrapat);
    DrawFormattedText(w,prac6aright,objs_right_sx,objs_sy,black,wrapat);
    Screen('Flip',w);
end

tic;
while toc < choice_time
    Screen('PutImage',w,trap,choice_loc);
    DrawFormattedText(w,prac6b,'center','center',black,wrapat);
    Screen('Flip', w);
end

tic;
while toc < quest_time
    DrawFormattedText(w,prac6c,'center','center',black,wrapat);
    Screen('Flip',w);
end  

tic;
while toc < iti
    DrawFormattedText(w,'+','center','center',black,wrapat);
    Screen('Flip',w);
end

%ball can plant - ball
tic;
while toc < objs_time
    Screen('PutImage',w,ball,objs_loc_left);
    Screen('PutImage',w,can,objs_loc_center);
    Screen('PutImage',w,plant,objs_loc_right);
    DrawFormattedText(w,prac7a,'center',setup_text,black,wrapat);
    DrawFormattedText(w,prac7aleft,objs_left_sx,objs_sy,black,wrapat);
    DrawFormattedText(w,prac7acenter,'center',objs_sy,black,wrapat);
    DrawFormattedText(w,prac7aright,objs_right_sx,objs_sy,black,wrapat);
    Screen('Flip',w);
end

tic;
while toc < choice_time
    Screen('PutImage',w,ball,choice_loc);
    DrawFormattedText(w,prac7b,'center','center',black,wrapat);
    Screen('Flip', w);
end

tic;
while toc < quest_time
    DrawFormattedText(w,prac7c,'center','center',black,wrapat);
    Screen('Flip',w);
end

tic;
while toc < iti
    DrawFormattedText(w,'+','center','center',black,wrapat);
    Screen('Flip',w);
end

%compass ball lipstick - lipstick
tic;
while toc < objs_time
    Screen('PutImage',w,compass,objs_loc_left);
    Screen('PutImage',w,ball,objs_loc_center);
    Screen('PutImage',w,lipstick,objs_loc_right);
    DrawFormattedText(w,prac8a,'center',setup_text,black,wrapat);
    DrawFormattedText(w,prac8aleft,objs_left_sx,objs_sy,black,wrapat);
    DrawFormattedText(w,prac8acenter,'center',objs_sy,black,wrapat);
    DrawFormattedText(w,prac8aright,objs_right_sx,objs_sy,black,wrapat);
    Screen('Flip',w);
end

tic;
while toc < choice_time
    Screen('PutImage',w,lipstick,choice_loc);
    DrawFormattedText(w,prac8b,'center','center',black,wrapat);
    Screen('Flip', w);
end

tic;
while toc < quest_time
    DrawFormattedText(w,prac8c,'center','center',black,wrapat);
    Screen('Flip',w);
end

tic;
while toc < iti
    DrawFormattedText(w,'+','center','center',black,wrapat);
    Screen('Flip',w);
end

KbQueueFlush(kbd_devs(end));
KbQueueStart(kbd_devs(end)); 
DrawFormattedText(w,instend,'center','center',black,wrapat2);
Screen('Flip',w);
KbQueueWait(kbd_devs(end));
WaitSecs(.5);
KbQueueStop(kbd_devs(end));

KbQueueRelease(kbd_devs(end));
clear screen

catch
    Screen('CloseAll');
    ShowCursor;
    ListenChar(0);
    Priority(0);
    rethrow(lasterror);
end